<?php
include('../data/comm.inc.php');
include('../data/myadminvar.php');
include('../func/func.php');
include('../func/csfunc.php');

include('../func/adminfunc.php');
include('../include.php');
include('./checklogin.php');

switch ($_REQUEST['xtype']) {
    case "show":
        $game = getgamecs($userid);
        $game = getgamename($game);
        
        if (in_array($_REQUEST['gid'], $garr)) {
            $gid = $_REQUEST['gid'];
        }
        $msql->query("select * from `$tb_game` where gid='$gid'");
        $msql->next_record();
        $ftype = json_decode($msql->f('ftype'), true);
        
        $gname = $msql->f('gname');
		$flname = $msql->f('flname');
        $warn  = array();
        foreach ($ftype as $key => $val) {
            $warn[$key]['name'] = $val['name'];
            $fsql->query("select je,ks from `$tb_warn` where userid='$userid' and gid='$gid' and class='$key'");
            $fsql->next_record();
            $warn[$key]['ftype'] = $key;
            $warn[$key]['je']    = pr0($fsql->f('je'));
            $warn[$key]['ks']    = pr0($fsql->f('ks'));
            $warn[$key]['gname'] = $gname;
        }
        $tpl->assign("gid", $gid);
		$tpl->assign("flname", $flname);
        $tpl->assign("game", $game);
        $tpl->assign("warn", $warn);
        $tpl->display("warn.html");
        break;
    case "setwarn":
        $arr = str_replace('\\', '', $_POST['str']);
        $gid = $_POST['gid'];
        $arr = json_decode($arr, true);
        $ca  = count($arr);
        $msql->query("delete from `$tb_warn` where userid='$userid' and gid='$gid'");
        for ($i = 0; $i < $ca; $i++) {
            $sql = "insert into `$tb_warn` set je='" . $arr[$i]['je'] . "',ks='" . $arr[$i]['ks'] . "',gid='$gid',userid='$userid',class='" . $arr[$i]['ftype'] . "'";
            $msql->query($sql);
        }
		userchange("更改警示金额",$userid);
        echo 1;
        break;
    case 'auto':
             $game = getgamecs($userid);
        $game = getgamename($game);
        
        if (is_numeric($_REQUEST['gid']) & strlen($_REQUEST['gid']) == 3) {
            $gid = $_REQUEST['gid'];
        }
        $msql->query("select * from `$tb_game` where gid='$gid'");
        $msql->next_record();
        $ftype = json_decode($msql->f('ftype'), true);
        
        $gname = $msql->f('gname');
		$flname = $msql->f('flname');
        
        
        foreach ($ftype as $key => $val) {
            $msql->query("select * from `$tb_auto` where class='$key' and gid='$gid' and userid='$userid' ");
            $msql->next_record();
            $auto[$key]['ifok']       = $msql->f('ifok');
			$auto[$key]['yj']       = $msql->f('yj');
			$auto[$key]['qsnum']       = $msql->f('qsnum');
			$auto[$key]['qspeilv']       = (float)($msql->f('qspeilv'));
            $auto[$key]['startje']    = pr0($msql->f('startje'));
            $auto[$key]['startpeilv'] = (float)($msql->f('startpeilv'));
            $auto[$key]['stopje']     = pr0($msql->f('stopje'));
            $auto[$key]['addje']      = pr0($msql->f('addje'));
            $auto[$key]['attpeilv']   = (float)($msql->f('attpeilv'));
            $auto[$key]['lowpeilv']   = (float)($msql->f('lowpeilv'));
            $auto[$key]['ifzc']       = $msql->f('ifzc');
			$auto[$key]['name']       = $val['name'];
			$auto[$key]['gname']       = $gname;
			$auto[$key]['ftype'] = $key;
        }
        
        $tpl->assign('auto', $auto);
        $tpl->assign("gid", $gid);
		$tpl->assign("flname", $flname);
        $tpl->assign("game", $game);
        $tpl->display('auto.html');
        break;
    case 'setauto':
        $arr = str_replace('\\', '', $_POST['str']);
        $gid = $_POST['gid'];
        $arr = json_decode($arr, true);
        $ca  = count($arr);
        $msql->query("delete from `$tb_auto` where userid='$userid' and gid='$gid'");
        for ($i = 0; $i < $ca; $i++) {
            $ifok       = $arr[$i]['ifok'];
			$yj       = $arr[$i]['yj'];
			$qsnum       = $arr[$i]['qsnum'];
			$qspeilv      = $arr[$i]['qspeilv'];
			
            $ifzc       = $arr[$i]['ifzc'];
            $startje    = $arr[$i]['startje'];
            $startpeilv = $arr[$i]['startpeilv'];
            $stopje     = $arr[$i]['stopje'];
            $addje      = $arr[$i]['addje'];
            $attpeilv   = $arr[$i]['attpeilv'];
            $lowpeilv   = $arr[$i]['lowpeilv'];
            $ftype      = $arr[$i]['ftype'];
            $sql        = "insert into  `$tb_auto` set ifok='$ifok',yj='$yj',qsnum='$qsnum',qspeilv='$qspeilv',startje='$startje',stopje='$stopje',addje='$addje',attpeilv='$attpeilv'";
            $sql .= ",lowpeilv='$lowpeilv',startpeilv='$startpeilv',ifzc='$ifzc',class='$ftype',userid='$userid',gid='$gid'";
            $msql->query($sql);
        }

		userchange("更改自动降倍",$userid);
        echo 1;
        break;
	case "yiwotongbuwarn":
         $gid = $_POST['gid'];	
		 $msql->query("select gid from `$tb_game` where fenlei=(select fenlei from `$tb_game` where gid='$gid') and gid!='$gid'");
		 while($msql->next_record()){
			 $ngid = $msql->f('gid');
			 $fsql->query("delete from `$tb_warn` where gid='$ngid' and userid='$userid'");
			 $fsql->query("insert into `$tb_warn` select NULL,$ngid,$userid,class,je,ks from `$tb_warn` where gid='$gid' and userid='$userid'");
			 
		 }
        echo 1;
	break;
	case "yiwotongbuauto":
         $gid = $_POST['gid'];	
		 $msql->query("select gid from `$tb_game` where fenlei=(select fenlei from `$tb_game` where gid='$gid') and gid!='$gid'");
		 while($msql->next_record()){
			 $ngid = $msql->f('gid');
			 $fsql->query("delete from `$tb_auto` where gid='$ngid' and userid='$userid'");
			 $fsql->query("insert into `$tb_auto` select NULL,$ngid,class,$userid,ifok,startje,startpeilv,addje,attpeilv,lowpeilv,stopje,ifzc,yj,qsnum,qspeilv from `$tb_auto` where gid='$gid' and userid='$userid'");
			 
		 }
        echo 1;
	break;
}
?>